package com.company.finance.ddd.domain.core.voucher.rule.concrete;

import com.company.finance.ddd.common.FlagEnum;
import com.company.finance.ddd.domain.core.voucher.enums.VoucherSubjectEnum;
import com.company.finance.ddd.domain.core.voucher.rule.*;
import com.company.finance.ddd.domain.core.bill.enums.BillSubTypeEnum;
import org.springframework.stereotype.Component;

/**
 * @author wanglei
 */
@Component
public class ShouldPayRuleHolder extends RuleHolder {

    @Override
    public RuleDefinition createRuleDefinition() {
        return RuleDefinition.builder().voucherType(VoucherType.builder().code("00").name("应付").build())
                .addBillSpecification(buildBillSpecificationForSupplierExpenseWithPnRn())
                .addBillSpecification(buildBillSpecificationForSupplierExpenseWithPnRy())
                .addBillSpecification(buildBillSpecificationForPurchaseExpense())
                .addBillSpecification(buildBillSpecificationForFinger())
                .addBillSpecification(buildBillSpecificationForFingerWithPnRy())
                .build();
    }

    private RuleDefinition.BillSpecification buildBillSpecificationForFingerWithPnRy() {
        return RuleDefinition.BillSpecification.builder()
                .billSubTypeEnum(BillSubTypeEnum.FINGER)
                .prepayment(FlagEnum.NO).relateDeal(FlagEnum.YES)
                .billItemRule(BillItemRule.builder()
                        .creditSubject(VoucherSubjectEnum.COST)
                        .debitSubject(VoucherSubjectEnum.BANK)
                        .creditDigestRule(BillItemRule.DigestRule.builder()
                                .layout("companyName付empName个人报销feeItemName")
                                .placeholder(new String[]{"companyName", "empName", "feeItemName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .debitDigestRule(BillItemRule.DigestRule.builder()
                                .layout("empName收到companyName个人报销")
                                .placeholder(new String[]{"companyName", "empName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .build())
                .build();
    }

    private RuleDefinition.BillSpecification buildBillSpecificationForFinger() {
        return RuleDefinition.BillSpecification.builder()
                .billSubTypeEnum(BillSubTypeEnum.FINGER)
                .prepayment(FlagEnum.NO).relateDeal(FlagEnum.NO)
                .billItemRule(BillItemRule.builder()
                        .creditSubject(VoucherSubjectEnum.COST)
                        .debitSubject(VoucherSubjectEnum.BANK)
                        .creditDigestRule(BillItemRule.DigestRule.builder()
                                .layout("companyName付empName个人报销feeItemName")
                                .placeholder(new String[]{"companyName", "empName", "feeItemName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .debitDigestRule(BillItemRule.DigestRule.builder()
                                .layout("empName收到companyName个人报销")
                                .placeholder(new String[]{"companyName", "empName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .build())
                .build();
    }

    private RuleDefinition.BillSpecification buildBillSpecificationForPurchaseExpense() {
        return RuleDefinition.BillSpecification.builder()
                .billSubTypeEnum(BillSubTypeEnum.PURCHASE_EXPENSE)
                .prepayment(FlagEnum.NO).relateDeal(FlagEnum.NO)
                .billItemRule(BillItemRule.builder()
                        .creditSubject(VoucherSubjectEnum.COST)
                        .creditDigestRule(BillItemRule.DigestRule.builder()
                                .layout("companyName应付supplierName")
                                .placeholder(new String[]{"companyName", "supplierName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .debitSubject(VoucherSubjectEnum.FIXED_ASSETS)
                        .debitDigestRule(BillItemRule.DigestRule.builder()
                                .layout("supplierName应收companyName")
                                .placeholder(new String[]{"companyName", "supplierName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .build())
                .build();
    }

    private RuleDefinition.BillSpecification buildBillSpecificationForSupplierExpenseWithPnRy() {
        return RuleDefinition.BillSpecification.builder()
                .billSubTypeEnum(BillSubTypeEnum.SUPPLIER_EXPENSE)
                .prepayment(FlagEnum.NO).relateDeal(FlagEnum.YES)
                .billItemRule(BillItemRule.builder()
                        .creditSubject(VoucherSubjectEnum.FIXED_ASSETS)
                        .debitSubject(VoucherSubjectEnum.BANK)
                        .creditDigestRule(BillItemRule.DigestRule.builder()
                                .layout("companyName应付supplierName")
                                .placeholder(new String[]{"companyName", "supplierName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .debitDigestRule(BillItemRule.DigestRule.builder()
                                .layout("supplierName应收companyName")
                                .placeholder(new String[]{"companyName", "supplierName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .build())
                .build();
    }

    private RuleDefinition.BillSpecification buildBillSpecificationForSupplierExpenseWithPnRn() {
        return RuleDefinition.BillSpecification.builder()
                .billSubTypeEnum(BillSubTypeEnum.SUPPLIER_EXPENSE)
                .prepayment(FlagEnum.NO).relateDeal(FlagEnum.NO)
                .billItemRule(BillItemRule.builder()
                        .creditSubject(VoucherSubjectEnum.FIXED_ASSETS)
                        .debitSubject(VoucherSubjectEnum.BANK)
                        .creditDigestRule(BillItemRule.DigestRule.builder()
                                .layout("companyName应付supplierName")
                                .placeholder(new String[]{"companyName", "supplierName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .debitDigestRule(BillItemRule.DigestRule.builder()
                                .layout("supplierName应收companyName")
                                .placeholder(new String[]{"companyName", "supplierName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .build())
                .build();
    }
}
